package com.song.email.util.email;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.song.email.util.common.Cons;

public class EmailProtocol {
	private static Log log = LogFactory.getLog(EmailProtocol.class);
	
	public static String getProtocol(String emailAddress,String protocolType){
		if(StringUtils.isBlank(emailAddress) || StringUtils.isBlank(protocolType)){
			log.error("获取邮件协议时邮件地址或者协议类型为空.");
		}
		String [] s = emailAddress.split("@");
		if(protocolType.equals(Cons.EMAIL_PROTOCOL_POP3)){
			return "pop3." + s[1];
		}else if(protocolType.equals(Cons.EMAIL_PROTOCOL_Smtp)){
			if(s[1].indexOf("sina") >= 0){
				return "smtp.sina.com.cn";
			}if(s[1].indexOf("1ypg") >= 0){
				return "smtp.ym.163.com";
			}else{
				return "smtp." + s[1];
			}
		}else{
			return null;
		}
	}
}
